package com.situ.shopuser.controller;

import com.situ.shoplook.common.model.Product;
import com.situ.shoplook.common.service.CategoryService;
import com.situ.shoplook.common.service.ProductService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author:yzy
 * @date:2024/9/4
 */
@RestController
@RequestMapping
public class ProController {
    @DubboReference
    private ProductService productService;
    @DubboReference
    private CategoryService categoryService;

    @GetMapping("/product/{id}")
    public Product showProduct(@PathVariable(value = "id") Integer id) {
        Product product = productService.findOneProduct(id);
        System.out.println("product:" + product);
        return product;
    }

    @GetMapping("/product/findCategory/{categoryId}")
    public List<Product> showProducts(@PathVariable(value = "categoryId") Integer categoryId) {
        List<Integer> categoryIds = new ArrayList<>();
        categoryIds  = categoryService.findChildren(categoryId);
        List<Product> products = productService.findByIds(categoryIds);
        System.out.println("products:" + products);
        return products;
    }
}
